package com.scnu.hachimi.element;

import com.scnu.hachimi.manager.ObjectManager;
import com.scnu.hachimi.manager.ResourcesManager;

import java.awt.*;

public class Player extends Tank {
    private Color color;  //子弹颜色
    private long loadTime;
    public int hp;
    private int atk;
    private int bulletSpeed;
    private int bulletSize;
    private long lastFireTime = 0;

    public boolean isAlive = true;


    public Player(String img, int x, int y, int width, int height,
               int speed, int atk, long loadTime, int bulletSpeed, int bulletSize,
               String upImg, String downImg, String leftImg, String rightImg,
               Color color, int hp, ObjectManager om) {

        super(img, x, y, width, height, speed, upImg, downImg, leftImg, rightImg, om);
        this.color = color;
        this.hp = hp;
        this.loadTime = loadTime;
        this.atk = atk;
        this.bulletSpeed = bulletSpeed;
        this.bulletSize = bulletSize;
    }

    @Override
    public void paintSelf(Graphics g, ResourcesManager rm) {
        Image img = rm.imageMap.get(this.img);
        g.drawImage(img, x, y,w,h, null);
    }

    @Override
    public Rectangle getRect() {
        return new Rectangle(x + 4, y + 4, w - 8, h - 8);
    }

    public void attack() {
        long now = System.currentTimeMillis();
        if (now - lastFireTime >= loadTime) {
            lastFireTime = now;
            Point headPoint = getHeadPoint();
            om.bullet.add(new Bullet("", headPoint.x, headPoint.y, bulletSize, bulletSize, bulletSpeed, atk, direct, color,  true));
        }
    }



}
